<template>
  <div v-loading.lock="loading" class="base-content">
    <div class="basic-info">
      <el-form :inline="true" :model="queryForm">
        <el-form-item label="任务Id">
          <el-input v-model="queryForm.entrustTaskId" placeholder="任务Id" />
        </el-form-item>
        <el-form-item label="检测项目Id">
          <el-input v-model="queryForm.detectionItemId" placeholder="检测项目Id" />
        </el-form-item>
        <el-form-item label="检测结果">
          <el-input v-model="queryForm.result" placeholder="检测结果" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onQuery">查询</el-button>
          <el-button type="primary" @click="onNew">新增</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :data="list"
        element-loading-text="Loading"
        highlight-current-row
      >
        <el-table-column align="center" label="序号" width="50">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="任务Id">
          <template slot-scope="scope">
            {{ scope.row.entrustTaskId }}
          </template>
        </el-table-column>
        <el-table-column label="检测项目Id">
          <template slot-scope="scope">
            {{ scope.row.detectionItemId }}
          </template>
        </el-table-column>
        <el-table-column label="检测结果">
          <template slot-scope="scope">
            {{ scope.row.result }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
          <div class="base-table-operation">
            <el-link size="mini" type="primary" @click="handleEdit(scope.row)"
              >编辑</el-link
            >
            <el-link
              size="mini"
              type="danger"
              @click="handleDelete(scope.row)"
              >删除</el-link
            >
          </div>
          </template>
        </el-table-column>
      </el-table>

      <BasePagination
        :total="pagination.total"
        :page-index="pagination.pageIndex"
        :page-size="pagination.pageSize"
        @sizeChange="sizeChange"
        @currentChange="currentChange"
      />
    </div>

    <EntrustTaskDetectionItemEdit
      ref="EntrustTaskDetectionItemEdit"
      :dialog-form-visible.sync="dialogFormVisible"
    />
  </div>
</template>

<script>
import { deleteRecord, getList } from "../../../api/EntrustTaskManage/EntrustTaskDetectionItem.js";
import EntrustTaskDetectionItemEdit from "./EntrustTaskDetectionItemEdit.vue";

export default {
  name: "EntrustTaskDetectionItemList",
  components: { EntrustTaskDetectionItemEdit },
  data() {
    return {
      loading: true,
      list: [],
      queryForm: {
        entrustTaskId: 0,
        detectionItemId: 0,
        result: "",
      },
      dialogFormVisible: false,
      pagination: {
        pageIndex: 1,
        pageSize: 10,
        total: 0,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    currentChange(val) {
      this.pagination.pageIndex = val;
      this.getList();
    },
    sizeChange(val) {
      this.pagination.pageIndex = 1;
      this.pagination.pageSize = val;
      this.getList();
    },
    getList() {
      this.loading = true;
      getList(this.queryForm, this.pagination)
        .then((res) => {
          this.list = res.data.dataList ? res.data.dataList : [];
          this.pagination.total = res.data.total;
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    onNew() {
      this.$refs.EntrustTaskDetectionItemEdit.formData = this.Helper.deepCopy(
        this.$refs.EntrustTaskDetectionItemEdit.initData
      );
      this.dialogFormVisible = true;
    },
    handleDelete(rowData) {
      this.Helper.deleteConfirm(() => {
        this.loading = true;
        deleteRecord({ id: rowData.id })
          .then((res) => {
            this.getList();
            this.loading = false;
          })
          .catch(() => {
            this.loading = false;
          });
      });
    },
    handleEdit(rowData) {
      this.$refs.EntrustTaskDetectionItemEdit.formData = rowData;
      this.dialogFormVisible = true;
    },
    onQuery() {
      this.getList();
    },
  },
};
</script>
